package com.foo.DataProvider;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

public class ProviderClient 
{
	ProviderRemote dataprovider = null;
	public ProviderClient()
	{
		try
		{
			Properties properties = new Properties();
			properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");
			properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
			properties.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
			Context ctx = new InitialContext(properties);
			Object ref = ctx.lookup("Provider/remote");
			//DataProviderRemote 
			dataprovider = (ProviderRemote) PortableRemoteObject.narrow(ref, ProviderRemote.class);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}	
	}  
	public void getData(String sorttype,String value, Timestamp timestamp, Date fromdate, Date todate)
	{
		dataprovider.getData(sorttype, value, timestamp, fromdate, todate);
		System.out.println("Sending data to server");
	}

}
